package weiyao.xinxidasai.mapper;

import org.apache.ibatis.annotations.*;
import weiyao.xinxidasai.pojo.NotaFiles;

@Mapper
public interface NotaFilesMapper {

    @Insert("INSERT INTO nota_files (user_id, version_id, encrypted_at, original_hash, encrypted_hash,original_length) " +
            "VALUES (#{userId}, #{versionId}, #{encryptedAt}, #{originalHash}, #{encryptedHash},#{originalLength})")
    @Options(useGeneratedKeys = true, keyProperty = "fileId")
    int insertNotaFile(NotaFiles notaFile);

    @Select("SELECT * FROM nota_files WHERE original_hash = #{originalHash}")
    NotaFiles findByOriginalHash(String originalHash);

    @Delete("DELETE FROM nota_files WHERE file_id = #{fileId}")
    int deleteByFileId(Long fileId);
    @Select("SELECT * FROM nota_files WHERE encrypted_hash = #{encryptedHash}")
    NotaFiles findByEncryptedHash(String encryptedHash);
    @Select("SELECT * FROM nota_files WHERE user_id = #{userId} AND original_length = #{length} LIMIT 1")
    NotaFiles findByTokenAndLength(@Param("userId") Long userId, @Param("token") String token, @Param("length") int length);

    @Select("SELECT * FROM nota_files WHERE file_id = #{fileId}")
    NotaFiles findByFileId(@Param("fileId") Long fileId);

}